using UnityEngine;
using UnityEngine.UI;
public class JoinRoomView : WindowView
{
    public Text[] texts;
    private int currentIndex = 0;
    public override void Start()
    {
        base.Start();
        OnReInputButton();
    }
    public void OnNumButton(int number)
    {
        if (currentIndex < texts.Length)
        {
            texts[currentIndex].text = number + "";
            currentIndex++;
            if (currentIndex == texts.Length)
            {
                JoinRoom();
            }
        }
    }
    public void OnReInputButton()
    {
        currentIndex = 0;
        for (var i = 0; i < texts.Length; i++)
        {
            texts[i].text = null;
        }
    }
    public void OnDeleteButton()
    {
        if (currentIndex > 0)
        {
            currentIndex--;
            texts[currentIndex].text = null;
        }
    }
    private void JoinRoom()
    {
        string roomIDStr = "";
        for (var i = 0; i < texts.Length; i++)
        {
            roomIDStr = roomIDStr.Insert(roomIDStr.Length, texts[i].text);
        }
        ((JoinRoomLogic)logic).JoinRoom(int.Parse(roomIDStr));
    }
}